define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'project/index/index' + location.search,
                    add_url: 'project/index/add',
                    edit_url: 'project/index/edit',
                    del_url: 'project/index/del',
                    multi_url: 'project/index/multi',
                    table: 'project',
                }
            });
//             var table = $("#table");
// //给添加按钮添加`data-area`属性
//             $(".btn-add").data("area", ["100%", "100%"]);
// //当内容渲染完成给编辑按钮添加`data-area`属性
//             table.on('post-body.bs.table', function (e, settings, json, xhr) {
//                 $(".btn-editone").data("area", ["100%", "100%"]);
//             });
            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showToggle: false,
                showColumns: false,
                visible: false,
                showExport: false,
                commonSearch: false,
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        // {field: 'order', title: __('Order')},
                        {field: 'method_name', title: __('TodayMethod')},
                        {field: 'name', title: __('Name')},
                        {field: 'budget', title: __('Budget')},
                        {field: 'offer', title: __('Offer')},
                        {field: 'is_run', title: __('Is_run'),searchList: {"1":__('Yes'),"0":__('No')}, formatter: Table.api.formatter.toggle},
                        // {field: 'project_url', title: __('Project_url'), formatter: Table.api.formatter.url},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,  buttons: [
                                {
                                    name: 'detail',
                                    title: __('日程管理'),
                                    classname: 'btn btn-xs btn-primary',
                                    icon: 'fa fa-list',
                                    url: 'project/detail/index?project_id={id}',
                                }],formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});